﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace BitPortal.Modules.Login
{
    public partial class Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
            {
                LoginUser.DestinationPageUrl = HttpUtility.UrlDecode(Request.QueryString["ReturnUrl"]);
            }
            else
            {
                LoginUser.DestinationPageUrl = Request.Url.PathAndQuery;
            }
        }
        protected void LoginUser_LoginError(object sender, EventArgs e)
        {
            MembershipUser u = Membership.GetUser(LoginUser.UserName);
            if (u != null)
            {
                if (!u.IsApproved)
                {
                    LoginUser.FailureText = Resources.BitResources.Login_AccountNotApproved;
                    return;
                }

                if (u.IsLockedOut)
                {
                    LoginUser.FailureText = Resources.BitResources.Login_AccountIsLoged;
                    return;
                }
            }
            // Default message
            LoginUser.FailureText = Resources.BitResources.Login_AccountWrong;
        }

        //protected void LoginUser_OnLoggedIn(object sender, EventArgs e)
        //{
        //    (this.Page as Controls.BaseFrontendPage).RegisterScript("Boxy.get(jQuery('#QuickLoginPanel')).hide();");
        //}

    }
}